<?php

class Bid_Form_Item extends Front_Base_Form_Horizontal
{
    public function getFormId()
    {
        $className = get_class($this);
        return strtolower($className);
    }

    public function init()
    {
        $this->setIsArray(true);
        //$this->setElementsBelongTo('bootstrap');

        $this->_addClassNames('form-horizontal');

        // Item title
        $this->addElement('text', 'frmItemNew', array(
            'id' => 'frmItemNew',
            'label' => $this->getView()->translate('BID_ITEM_TITLE'),
            'class' => 'input inputTitle',
        ));
        $this->getElement('frmItemNew')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('stringLength', false, array(3, 255)),
        ));

        // Category
        $this->addElement('select', 'frmItemCat', array(
            'id' => 'frmItemCat',
            'label' => $this->getView()->translate('BID_ITEM_CATEGORY'),
            'multiOptions' => array('1' => 'Điện thoại', '2' => 'Máy tính - Laptop'),
            'class' => 'input inputCategory'
        ));
        $this->getElement('frmItemCat')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true)
        ));

        // Sub-Category
        $this->addElement('select', 'frmItemSubCat', array(
            'id' => 'frmItemSubCat',
            'multiOptions' => array('1' => 'Điện thoại phổ thông', '2' => 'Điện thoại thông minh'),
            'class' => 'input inputCategory'
        ));
        $this->getElement('frmItemSubCat')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true)
        ));

        $this->addElement('radio', 'frmItemChosen', array(
            'label' => $this->getView()->translate('BID_ITEM_STATUS'),
            'multiOptions'=>array(
                '1' => $this->getView()->translate('BID_ITEM_STATUS_NEW'),
                '2' => $this->getView()->translate('BID_ITEM_STATUS_OLD'),
            ),
        ));
        $this->getElement('frmItemChosen')
        ->setAttrib('label_class', 'label2')
        ->setSeparator(' ')
        ->setValue(1);


        // Start price
        $this->addElement('text', 'frmItemStart', array(
            'id' => 'frmItemStart',
            'label' => $this->getView()->translate('BID_ITEM_START_PRICE'),
            'maxlength' => 255,
            'class' => 'input'
        ));
        $this->getElement('frmItemStart')
        ->addDecorator('Label', array('class' => 'label1 label3'))
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('Int')
        ));

        // Reserve price
        $this->addElement('text', 'frmItemReserve', array(
            'id' => 'frmItemReserve',
            'label' => $this->getView()->translate('BID_ITEM_RESERVE_PRICE'),
            'maxlength' => 255,
            'class' => 'input'
        ));
        $this->getElement('frmItemReserve')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('Int')
        ));

        // Buy now price
        $this->addElement('text', 'frmItemSellnow', array(
            'id' => 'frmItemSellnow',
            'label' => $this->getView()->translate('BID_ITEM_BUYNOW_PRICE'),
            'maxlength' => 255,
            'class' => 'input'
        ));
        $this->getElement('frmItemSellnow')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('Int')
        ));

        // Check box
        $this->addElement('checkbox', 'frmItemNoReserve', array(
            'id' => 'frmItemNoReserve',
            'class' => 'inputPrice'
        ));
        $this->getElement('frmItemNoReserve')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('Int')
        ));

        // Bid step price
        $this->addElement('select', 'frmItemBidStep', array(
            'id' => 'frmItemBidStep',
            'label' => $this->getView()->translate('BID_ITEM_STEP_PRICE'),
            'multiOptions' => array('100000'=>'100.000đ', '200000'=>'200.000đ', '500000'=>'500.000đ', '1000000'=>'1.000.000đ', '2000000'=>'2.000.000đ', '5000000'=>'5.000.000đ'),
            'class' => 'input'
        ));
        $this->getElement('frmItemBidStep')
        ->addDecorator('Label', array('class' => 'label5'))
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true)
        ));
        
        // Bid end date
        $this->addElement('select', 'frmItemEnd', array(
            'id' => 'frmItemEnd',
            'label' => $this->getView()->translate('BID_ITEM_END_DATE'),
            'multiOptions' => array('1'=>'1 ngày', '2'=>'2 ngày', '3'=>'3 ngày', '4'=>'4 ngày', '5'=>'5 ngày', '7'=>'1 tuần'),
            'class' => 'input'
        ));
        $this->getElement('frmItemEnd')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true)
        ));

        // Fulltext
        $this->addElement('wysiwyg', 'frmItemDescription', array(
            'id' => 'frmItemDescription',
            /*'label' => $this->getView()->translate('BID_ITEM_DESCRIPTION'),*/
            'editorToolbar' => 'custom',
            'editorCustomConfig' => array(array('Source', '-', 'Bold', 'Italic', 'Underline')),
            'editorHeight' => '200'
        ));
        $this->getElement('frmItemDescription')
        ->addFilter('StringTrim')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true)
        ));

        // Featured Image
        $config = Zend_Registry::get('configuration');
        $this->addElement('file', 'file', array(
            'id' => 'file',
            'label' => $this->getView()->translate('BID_ITEM_IMAGE')
        ));
        $this->getElement('file')
        ->setDestination($config->upload->path . DS . 'images' . DS . 'bid')
        ->setMaxFileSize($config->upload->image->maxsize)
        ->addValidators(array(
            array('Count', false, 1),
            array('Size', false, $config->upload->image->maxsize),
            array('Extension', false, explode(',', $config->upload->image->extension)),
            //array('MimeType', false, explode(',', $config->upload->image->mimetype))
        ))
        ->setRequired(true);

        // Featured Image preview
        $this->addElement('render', 'features_image', array(
            'id' => 'features_image',
            'viewPath' => 'form/element-image-preview.phtml'
        ));
        
        // Gallery
        $config = Zend_Registry::get('configuration');
        $this->addElement('file', 'files', array(
            'id' => 'files',
            'label' => $this->getView()->translate('BID_ITEM_GALLERIES')
        ));
        $this->getElement('files')
        ->setDestination($config->upload->path . DS . 'images' . DS . 'bid' . DS . 'galleries')
        ->setMaxFileSize($config->upload->image->maxsize)
        ->addValidators(array(
            array('Count', false, array('min'=>1,'max'=>10)),
            array('Size', false, $config->upload->image->maxsize),
            array('Extension', false, explode(',', $config->upload->image->extension)),
            //array('MimeType', false, explode(',', $config->upload->image->mimetype))
        ))
        ->setAttrib('multiple', true)
        ->setIsArray(true);

        // Id
        $this->addElement('hidden', 'id', array(
            'id' => $this->getFormId() . '_id'
        ));
        $this->getElement('id')->removeDecorator('Wrapper')->removeDecorator('HtmlTag');
    }

}